package com.ruoyi.training.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.training.domain.ExamSchedule;
import com.ruoyi.training.service.IExamScheduleService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 考试安排Controller
 *
 * @author lqx
 * @date 2025-10-30
 */
@RestController
@RequestMapping("/examSchedule")
public class ExamScheduleController extends BaseController
{
    @Autowired
    private IExamScheduleService examScheduleService;

    /**
     * 查询考试安排列表
     */
    @RequiresPermissions("training:examSchedule:list")
    @GetMapping("/list")
    public TableDataInfo list(ExamSchedule examSchedule)
    {
        startPage();
        List<ExamSchedule> list = examScheduleService.selectExamScheduleList(examSchedule);
        return getDataTable(list);
    }

    /**
     * 导出考试安排列表
     */
    @RequiresPermissions("training:examSchedule:export")
    @Log(title = "考试安排", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ExamSchedule examSchedule)
    {
        List<ExamSchedule> list = examScheduleService.selectExamScheduleList(examSchedule);
        ExcelUtil<ExamSchedule> util = new ExcelUtil<ExamSchedule>(ExamSchedule.class);
        util.exportExcel(response, list, "考试安排数据");
    }

    /**
     * 获取考试安排详细信息
     */
    @RequiresPermissions("training:examSchedule:query")
    @GetMapping(value = "/{examScheduleId}")
    public AjaxResult getInfo(@PathVariable("examScheduleId") String examScheduleId)
    {
        return success(examScheduleService.selectExamScheduleByExamScheduleId(examScheduleId));
    }

    /**
     * 通过班级id获取考试安排详细信息
     * lqx
     */
    @GetMapping(value = "/getByClassId/{trainingClassId}")
    public AjaxResult getByClassId(@PathVariable("trainingClassId") String trainingClassId)
    {
        return success(examScheduleService.selectExamScheduleByClassId(trainingClassId));
    }

    /**
     * 新增考试安排
     */
//    @RequiresPermissions("training:examSchedule:add")
    @Log(title = "考试安排", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ExamSchedule examSchedule)
    {
        return toAjax(examScheduleService.insertExamSchedule(examSchedule));
    }

    /**
     * 修改考试安排
     */
//    @RequiresPermissions("training:examSchedule:edit")
    @Log(title = "考试安排", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ExamSchedule examSchedule)
    {
        return toAjax(examScheduleService.updateExamSchedule(examSchedule));
    }

    /**
     * 删除考试安排
     */
    @RequiresPermissions("training:examSchedule:remove")
    @Log(title = "考试安排", businessType = BusinessType.DELETE)
    @DeleteMapping("/{examScheduleIds}")
    public AjaxResult remove(@PathVariable String[] examScheduleIds)
    {
        return toAjax(examScheduleService.deleteExamScheduleByExamScheduleIds(examScheduleIds));
    }
}
